home *** CD-ROM | disk | FTP | other *** search
/ Amiga Format CD 43 / Amiga Format CD43 (1999)(Future Publishing)(GB)(Track 1 of 2)[!][issue 1999-09].iso / -serious- / programming / c / supralib / developer / source.org / recdirtags.c < prev    next >
C/C++ Source or Header  |  1999-06-14  |  6KB  |  167 lines

  1. /****** RecDirTags *****************************************************
  2. *
  3. *   NAME
  4. *       RecDirNextTagList -- Gets information about next file (V10)
  5. *       (dos V36)
  6. *
  7. *   SYNOPSIS
  8. *       error = RecDirNextTagList(RecDirInfo, RecDirFIB, TagItems)
  9. *
  10. *       UBYTE = RecDirNextTagList(struct RecDirInfo *, struct RecDirFIB *,
  11. *                   struct TagItem *);
  12. *
  13. *
  14. *       error = RecDirNextTags(RecDirInfo, RecDirFIB, tag1, ...)
  15. *
  16. *       UBYTE = RecDirNextTags(struct RecDirInfo *, struct RecDirFIB *,
  17. *                   ULONG tag1, ...);*
  18. *
  19. *
  20. *   FUNCTION
  21. *       This function does the same as RecDirNext() but it provides
  22. *       a TagList extension. Any additional tags will override initial
  23. *       settings in RecDirFIB structure.
  24. *
  25. *   INPUTS
  26. *       RecDirInfo - pointer to RecDirInfo structure which has been
  27. *                    called with RecDirInit()
  28. *       RecDirFIB  - pointer to initialized and set RecDirFIB structure,
  29. *                    or NULL.
  30. *                    You can get files' information either by setting
  31. *                    variables to this structure before calling
  32. *                    RecDirNextTagList(), or by providing TagItems you
  33. *                    want. 
  34. *                    NOTE: If you provide any TagItem then RecDirFIB will
  35. *                    be changed (if it's non-NULL)!
  36. *
  37. *       Tags - The following tags are available:
  38. *
  39. *           RD_NAME - File name will be provided. ti_Data should carry
  40. *                     a pointer to a string buffer (char *)
  41. *           RD_PATH - Directory path where scanned file is.
  42. *           RD_FULL - Full directory path + file name
  43. *           RD_SIZE - File lenght in bytes. ti_Data must have a pointer to
  44. *                     a LONG number (LONG *).
  45. *           RD_FLAGS - File's protection flags. ti_Data must have a pointer
  46. *                     to LONG.
  47. *           RD_COMMENT - File's comment note. ti_Data carries a pointer to
  48. *                     a string buffer.
  49. *           RD_DATE - File's DateStamp structure. Function will copy the
  50. *                     entire DateStamp structure into struct DateStamp
  51. *                     provided in ti_Data field that points to it.
  52. *           RD_BLOCKS - File size in blocks. ti_Data should have a pointer
  53. *                       to LONG
  54. *           RD_UID - Owner's UID (not supported with all file systems).
  55. *                    ti_Data should have a pointer to UWORD variable.
  56. *           RD_GID - Owner's GID. ti_Data has a pointer to UWORD variable.
  57. *           RD_FIB - FileInfoBlock. Function will copy examined file's
  58. *                    FileInfoBlock to a provided struct FileInfoBlock
  59. *                    via ti_Data (ti_Data has a pointer to an allocated
  60. *                    FileInfoBlock structure).
  61. *
  62. *   RESULT
  63. *       Same as for RecDirNext()
  64. *
  65. *   EXAMPLE
  66. *
  67. *       See an example for RecDirNext(). You can replace its line
  68. *
  69. *       RecDirNext(&rdi, &rdf);
  70. *          *with*
  71. *       RecDirNextTags(&rdi, NULL, RD_PATH, path,
  72. *                                  RD_NAME, name,
  73. *                                  RD_SIZE, &size,
  74. *                                  TAG_DONE);
  75. *   NOTES
  76. *       If RecDirFIB is not NULL, and you provide some tags as well then
  77. *       RecDirFIB will be changed. This may change in the future so
  78. *       that provided RecDirFIB will not change.
  79. *
  80. *   BUGS
  81. *       none found
  82. *
  83. *   SEE ALSO
  84. *       RecDirNext(), RecDirInit(), libraries/supra.h
  85. *
  86. ************************************************************************/
  87.  
  88. #include <proto/exec.h>
  89. #include <proto/utility.h>
  90. #include <exec/memory.h>
  91. #include <dos/dos.h>
  92. #include <utility/tagitem.h>
  93. #include <libraries/supra.h>
  94.  
  95.  
  96. UBYTE RecDirNextTagList(struct RecDirInfo *rdi, struct RecDirFIB *rdf,
  97.                     struct TagItem *tagList)
  98. {
  99. ULONG data;
  100. struct TagItem *tstate,*tag;
  101. UBYTE suc;
  102. UBYTE alloc = FALSE;
  103.  
  104. if (rdf == NULL) {
  105.     if ((rdf = AllocMem(sizeof(struct RecDirFIB), MEMF_CLEAR)) == NULL) {
  106.         return(RDI_ERR_MEM);
  107.     }
  108.     alloc = TRUE;
  109. }
  110.  
  111.     tstate = tagList;
  112.  
  113.     while (tag = NextTagItem(&tstate)) {
  114.         data = tag->ti_Data;
  115.         switch(tag->ti_Tag) {
  116.             case RD_NAME:
  117.                 rdf->Name = (char *)data;
  118.                 break;
  119.             case RD_PATH:
  120.                 rdf->Path = (char *)data;
  121.                 break;
  122.             case RD_FULL:
  123.                 rdf->Full = (char *)data;
  124.                 break;
  125.             case RD_SIZE:
  126.                 rdf->Size = (ULONG *)data;
  127.                 break;
  128.             case RD_FLAGS:
  129.                 rdf->Flags = (ULONG *)data;
  130.                 break;
  131.             case RD_COMMENT:
  132.                 rdf->Comment = (char *)data;
  133.                 break;
  134.             case RD_DATE:
  135.                 rdf->Date = (struct DateStamp *)data;
  136.                 break;
  137.             case RD_BLOCKS:
  138.                 rdf->Blocks = (ULONG *)data;
  139.                 break;
  140.             case RD_UID:
  141.                 rdf->UID = (UWORD *)data;
  142.                 break;
  143.             case RD_GID:
  144.                 rdf->GID = (UWORD *)data;
  145.                 break;
  146.             case RD_FIB:
  147.                 rdf->FIB = (struct FileInfoBlock *)data;
  148.                 break;
  149.         }
  150.     }
  151.  
  152.     suc = RecDirNext(rdi, rdf);
  153.     if (alloc == TRUE) FreeMem(rdf, sizeof(struct RecDirFIB));
  154.     return(suc);
  155. }
  156.  
  157. UBYTE RecDirNextTags(struct RecDirInfo *rdi, struct RecDirFIB *rdf, ULONG tagItem1, ...)
  158. {
  159.     UBYTE suc;
  160.  
  161.     suc = RecDirNextTagList(rdi, rdf, (struct TagItem *)&tagItem1);
  162.     return(suc);
  163. }
  164.  
  165.  
  166.  
  167.